/* I2S Digital Microphone Recording Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_log.h"
#include "esp_err.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

#include "sdkconfig.h"
#include "driver/i2s.h"
#include "esp_vfs_fat.h"
#include "esp_vfs.h" 
#include "user_sdspi.h" 
#include "user_max98357a.h" 
#include "user_ec11.h" 
#include "driver/spi_common.h"
#include "sdmmc_cmd.h"



static const char* TAG = "pdm_rec_example";
#define EC11_TASK_PRIO 11
#define MAX98357_TASK_PRIO 20

void app_main(void)
{
    ESP_LOGI(TAG, "PDM player Example start");
    mount_sdcard();

    test_sd_list();

    // Init the PDM digital microphone
    //init_i2s();


    
    
    xTaskCreatePinnedToCore(user_ec11_task, "EC11", 4096, NULL, EC11_TASK_PRIO, NULL, tskNO_AFFINITY);
    xTaskCreatePinnedToCore(user_max98357a_task, "MAX98357A", 8192, NULL, MAX98357_TASK_PRIO, NULL, tskNO_AFFINITY);

    play_index = 0;
    while(1)
    {
//        playback_wav(list[play_index].name);
        vTaskDelay(100);
    }
    // All done, unmount partition and disable SPI peripheral
    esp_vfs_fat_sdcard_unmount(SD_MOUNT_POINT, card);
    ESP_LOGI(TAG, "Card unmounted");
    // Deinitialize the bus after all devices are removed
    spi_bus_free(host.slot);

    // Stop I2S driver and destroy
    //ESP_ERROR_CHECK( i2s_driver_uninstall(I2S_NUM) );
}


